from django.db import models
from apps.users.models import BaseModel

ORGANIZATION_CATEGORY = (
    ("PXJG", "培训机构"),
    ("GR", "个人"),
    ("GX", "高校"),
)


# 城市
class City(BaseModel):
    name = models.CharField(verbose_name="名称", max_length=48)
    dec = models.CharField(verbose_name="描述", max_length=48)

    class Meta:
        verbose_name = "城市"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class CourseOrg(BaseModel):
    name = models.CharField(verbose_name="名称", max_length=48)
    desc = models.TextField(verbose_name="描述")
    tag = models.CharField(verbose_name="标签", max_length=24, default="")
    category = models.CharField(verbose_name="结构类型", default="PXJG", max_length=4, choices=ORGANIZATION_CATEGORY)
    image = models.ImageField(verbose_name="LOG", upload_to="org/%Y%m", default="default_org.jpg")
    address = models.CharField(verbose_name="地址", max_length=200)
    fav_nums = models.IntegerField(verbose_name="收藏人数", default=0)
    click_nums = models.IntegerField(verbose_name="点击人数", default=0)
    students = models.IntegerField(verbose_name="学习人数", default=0)
    course_nums = models.IntegerField(verbose_name="课程数", default=0)
    city = models.ForeignKey(City, verbose_name="所在城市", on_delete=models.CASCADE)

    class Meta:
        verbose_name = "机构"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 讲师
class Teacher(BaseModel):
    org = models.ForeignKey(CourseOrg, verbose_name="所属机构", on_delete=models.CASCADE)
    name = models.CharField(verbose_name="名称", max_length=48)
    age = models.IntegerField(verbose_name="年龄", default=18)
    work_years = models.IntegerField(verbose_name="工作年限", default=1)
    work_compy = models.CharField(verbose_name="就职公司", max_length=40)
    work_position = models.CharField(verbose_name="就职职位", max_length=40)
    points = models.CharField(verbose_name="教学特点", max_length=300)
    fav_nums = models.IntegerField(verbose_name="收藏人数", default=0)
    click_nums = models.IntegerField(verbose_name="点击人数", default=0)
    image = models.FileField(verbose_name="头像", upload_to="teacher/%Y%m", max_length=200)

    class Meta:
        verbose_name = "讲师"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
